Add GtkListBase
authorBenjamin Otte <otte@redhat.com>
Tue, 22 Oct 2019 06:01:16 +0000 (08:01 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 30 May 2020 23:26:46 +0000 (19:26 -0400)
This is a base item for GTK's list widgets so they can share some (read:
hopefully a lot of) code.

docs/reference/gtk/meson.build
gtk/gtk-autocleanups.h
gtk/gtk.h
gtk/gtkgridview.c
gtk/gtkgridview.h
gtk/gtklistbase.c [new file with mode: 0644]
gtk/gtklistbase.h [new file with mode: 0644]
gtk/gtklistbaseprivate.h [new file with mode: 0644]
gtk/gtklistview.c
gtk/gtklistview.h
gtk/meson.build

index e2aa759385cb823d03eb7d8577c544f0d6799542..b0e685f64aa43ea478a256b6b9044cb7510f1108 100644 (file)
@@ -132,6 +132,7 @@ private_headers = [
   'gtkimmoduleprivate.h',
   'gtkkineticscrollingprivate.h',
   'gtklabelprivate.h',
+  'gtklistbaseprivate.h',
   'gtklistitemprivate.h',
   'gtklistitemfactoryprivate.h',
   'gtklistitemmanagerprivate.h',
index 59474fc9672210c710c2c34e9b4efdcf3a282c78..f7bc1f30f18ad680dd3e8123501abb46286c11eb 100644 (file)
@@ -91,6 +91,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkGestureSingle, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkGestureSwipe, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkGestureZoom, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkGrid, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkGridView, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkHeaderBar, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkIMContext, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkIMContextSimple, g_object_unref)
@@ -103,6 +104,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkInfoBar, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLevelBar, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLinkButton, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkListStore, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkListView, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLockButton, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkMenuButton, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkMessageDialog, g_object_unref)
index 1a2f2111f43fbac38443c25f4de1c5293c9203d9..31cd5c8138517cab04270aa4fa3b635453f8eaa4 100644 (file)
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
 #include <gtk/gtklayoutmanager.h>
 #include <gtk/gtklayoutchild.h>
 #include <gtk/gtklevelbar.h>
+#include <gtk/gtklistbase.h>
 #include <gtk/gtklinkbutton.h>
 #include <gtk/gtklistbox.h>
 #include <gtk/gtklistitem.h>
index c5c6418f733082fff9a821d9d8c32c9cde8bd376..c8957519ec26e4e142e37173b4e29b9281a25f02 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "gtkadjustment.h"
 #include "gtkintl.h"
+#include "gtklistbaseprivate.h"
 #include "gtklistitemfactory.h"
 #include "gtklistitemmanagerprivate.h"
 #include "gtkmain.h"
@@ -58,7 +59,7 @@ typedef struct _CellAugment CellAugment;
 
 struct _GtkGridView
 {
-  GtkWidget parent_instance;
+  GtkListBase parent_instance;
 
   GListModel *model;
   GtkListItemManager *item_manager;
@@ -83,6 +84,11 @@ struct _GtkGridView
   GtkListItemTracker *focus;
 };
 
+struct _GtkGridViewClass
+{
+  GtkListBaseClass parent_class;
+};
+
 struct _Cell
 {
   GtkListItemManagerItem parent;
@@ -116,7 +122,7 @@ enum {
   LAST_SIGNAL
 };
 
-G_DEFINE_TYPE_WITH_CODE (GtkGridView, gtk_grid_view, GTK_TYPE_WIDGET,
+G_DEFINE_TYPE_WITH_CODE (GtkGridView, gtk_grid_view, GTK_TYPE_LIST_BASE,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
 
@@ -1991,8 +1997,6 @@ gtk_grid_view_init (GtkGridView *self)
 
   self->adjustment[GTK_ORIENTATION_HORIZONTAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
   self->adjustment[GTK_ORIENTATION_VERTICAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
-
-  gtk_widget_set_overflow (GTK_WIDGET (self), GTK_OVERFLOW_HIDDEN);
 }
 
 /**
@@ -2026,7 +2030,7 @@ gtk_grid_view_new (void)
  * argument, so you can write code like
  * ```
  *   grid_view = gtk_grid_view_new_with_factory (
- *     gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
+ *     gtk_builder_list_item_factory_newfrom_resource ("/resource.ui"));
  * ```
  *
  * Returns: a new #GtkGridView using the given @factory
index 5c42776dbeafa85e9e2fe36d633b7385f28d482f..cba7769401c297c8cf39716872c31d686c0c3794 100644 (file)
 #error "Only <gtk/gtk.h> can be included directly."
 #endif
 
-#include <gtk/gtkwidget.h>
+#include <gtk/gtklistbase.h>
 
 G_BEGIN_DECLS
 
 #define GTK_TYPE_GRID_VIEW         (gtk_grid_view_get_type ())
+#define GTK_GRID_VIEW(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_GRID_VIEW, GtkGridView))
+#define GTK_GRID_VIEW_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_GRID_VIEW, GtkGridViewClass))
+#define GTK_IS_GRID_VIEW(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_GRID_VIEW))
+#define GTK_IS_GRID_VIEW_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_GRID_VIEW))
+#define GTK_GRID_VIEW_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_GRID_VIEW, GtkGridViewClass))
+
+/**
+ * GtkGridView:
+ *
+ * GtkGridView is a list widget implementation that arranges its items in
+ * a grid.
+ */
+typedef struct _GtkGridView GtkGridView;
+typedef struct _GtkGridViewClass GtkGridViewClass;
 
 GDK_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkGridView, gtk_grid_view, GTK, GRID_VIEW, GtkWidget)
+GType           gtk_grid_view_get_type                          (void) G_GNUC_CONST;
 
 GDK_AVAILABLE_IN_ALL
 GtkWidget *     gtk_grid_view_new                               (void);
diff --git a/gtk/gtklistbase.c b/gtk/gtklistbase.c
new file mode 100644 (file)
index 0000000..ca93a53
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ */
+
+#include "config.h"
+
+#include "gtklistbaseprivate.h"
+
+G_DEFINE_ABSTRACT_TYPE (GtkListBase, gtk_list_base, GTK_TYPE_WIDGET)
+
+static void
+gtk_list_base_class_init (GtkListBaseClass *klass)
+{
+}
+
+static void
+gtk_list_base_init (GtkListBase *self)
+{
+  gtk_widget_set_overflow (GTK_WIDGET (self), GTK_OVERFLOW_HIDDEN);
+  gtk_widget_set_focusable (GTK_WIDGET (self), TRUE);
+}
+
diff --git a/gtk/gtklistbase.h b/gtk/gtklistbase.h
new file mode 100644 (file)
index 0000000..7b33ede
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ */
+
+#ifndef __GTK_LIST_BASE_H__
+#define __GTK_LIST_BASE_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkwidget.h>
+#include <gtk/gtklistitem.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_LIST_BASE         (gtk_list_base_get_type ())
+#define GTK_LIST_BASE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_LIST_BASE, GtkListBase))
+#define GTK_LIST_BASE_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_LIST_BASE, GtkListBaseClass))
+#define GTK_IS_LIST_BASE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_LIST_BASE))
+#define GTK_IS_LIST_BASE_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_LIST_BASE))
+#define GTK_LIST_BASE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_LIST_BASE, GtkListBaseClass))
+
+/**
+ * GtkListBase:
+ *
+ * GtkListBase is the abstract base class for GTK's list widgets.
+ */
+typedef struct _GtkListBase GtkListBase;
+typedef struct _GtkListBaseClass GtkListBaseClass;
+
+GDK_AVAILABLE_IN_ALL
+GType                   gtk_list_base_get_type                  (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif  /* __GTK_LIST_BASE_H__ */
diff --git a/gtk/gtklistbaseprivate.h b/gtk/gtklistbaseprivate.h
new file mode 100644 (file)
index 0000000..cfd704f
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ */
+
+#ifndef __GTK_LIST_BASE_PRIVATE_H__
+#define __GTK_LIST_BASE_PRIVATE_H__
+
+#include "gtklistbase.h"
+
+struct _GtkListBase
+{
+  GtkWidget parent_instance;
+};
+
+struct _GtkListBaseClass
+{
+  GtkWidgetClass parent_class;
+};
+
+
+#endif /* __GTK_LIST_BASE_PRIVATE_H__ */
index 828f442258ca39525fa6ce7da907bb7739ba2969..3a9e67dfc7e1f5e35f717e1f8b5732c06c3c59e1 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "gtkadjustment.h"
 #include "gtkintl.h"
+#include "gtklistbaseprivate.h"
 #include "gtklistitemmanagerprivate.h"
 #include "gtkmain.h"
 #include "gtkorientableprivate.h"
@@ -58,7 +59,7 @@ typedef struct _ListRowAugment ListRowAugment;
 
 struct _GtkListView
 {
-  GtkWidget parent_instance;
+  GtkListBase parent_instance;
 
   GListModel *model;
   GtkListItemManager *item_manager;
@@ -78,6 +79,11 @@ struct _GtkListView
   GtkListItemTracker *focus;
 };
 
+struct _GtkListViewClass
+{
+  GtkListBaseClass parent_class;
+};
+
 struct _ListRow
 {
   GtkListItemManagerItem parent;
@@ -110,7 +116,7 @@ enum {
   LAST_SIGNAL
 };
 
-G_DEFINE_TYPE_WITH_CODE (GtkListView, gtk_list_view, GTK_TYPE_WIDGET,
+G_DEFINE_TYPE_WITH_CODE (GtkListView, gtk_list_view, GTK_TYPE_LIST_BASE,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
 
@@ -1657,8 +1663,6 @@ gtk_list_view_init (GtkListView *self)
 
   self->adjustment[GTK_ORIENTATION_HORIZONTAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
   self->adjustment[GTK_ORIENTATION_VERTICAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
-
-  gtk_widget_set_overflow (GTK_WIDGET (self), GTK_OVERFLOW_HIDDEN);
 }
 
 /**
index 205cf8e9aa6bc1ba9fad9dc2781c06f52f4f5d1d..3d5f6a8a56970ff1943348ae06c9de72db0bd4ff 100644 (file)
 #error "Only <gtk/gtk.h> can be included directly."
 #endif
 
-#include <gtk/gtkwidget.h>
-#include <gtk/gtklistitem.h>
+#include <gtk/gtklistbase.h>
 
 G_BEGIN_DECLS
 
 #define GTK_TYPE_LIST_VIEW         (gtk_list_view_get_type ())
+#define GTK_LIST_VIEW(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_LIST_VIEW, GtkListView))
+#define GTK_LIST_VIEW_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_LIST_VIEW, GtkListViewClass))
+#define GTK_IS_LIST_VIEW(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_LIST_VIEW))
+#define GTK_IS_LIST_VIEW_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_LIST_VIEW))
+#define GTK_LIST_VIEW_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_LIST_VIEW, GtkListViewClass))
+
+/**
+ * GtkListView:
+ *
+ * GtkListView is the simple list implementation for GTK's list widgets.
+ */
+typedef struct _GtkListView GtkListView;
+typedef struct _GtkListViewClass GtkListViewClass;
 
 GDK_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkListView, gtk_list_view, GTK, LIST_VIEW, GtkWidget)
+GType           gtk_list_view_get_type                          (void) G_GNUC_CONST;
 
 GDK_AVAILABLE_IN_ALL
 GtkWidget *     gtk_list_view_new                               (void);
index c52e78ea6f82c29a1250a3ea2516161fb4ad4ebe..f89b8bf7d90aad1a0aed741da4c99225c4145496 100644 (file)
@@ -272,6 +272,7 @@ gtk_public_sources = files([
   'gtklayoutchild.c',
   'gtklayoutmanager.c',
   'gtklevelbar.c',
+  'gtklistbase.c',
   'gtklinkbutton.c',
   'gtklistbox.c',
   'gtklistitem.c',
@@ -544,6 +545,7 @@ gtk_public_headers = files([
   'gtklayoutmanager.h',
   'gtklevelbar.h',
   'gtklinkbutton.h',
+  'gtklistbase.h',
   'gtklistbox.h',
   'gtklistitem.h',
   'gtklistitemfactory.h',